﻿using UnityEngine;
using System.Collections.Generic;

public struct Int2Key : IEqualityComparer<Int2Key>
{
    public static Int2Key None = new Int2Key(0,0);

    public Int2Key(int _data1, int _data2)
    {
        this.data1 = _data1;
        this.data2 = _data2;
    }

    public int data1;
    public int data2;

    public bool Equals(Int2Key x, Int2Key y)
    {
        return x == y;
    }

    public override bool Equals(object y)
    {
        return y is Int2Key && this == (Int2Key)y;
    }

    public bool Equals(Int2Key y)
    {
        return this == y;
    }

    public override int GetHashCode()
    {
        int hashCode = data1.GetHashCode();
        if (hashCode != data2.GetHashCode())
            hashCode ^= data2.GetHashCode();
        return hashCode;
    }

    public int GetHashCode(Int2Key obj)
    {
        int hashCode = obj.data1.GetHashCode();
        if (hashCode != obj.data2.GetHashCode())
            hashCode ^= obj.data2.GetHashCode();
        return hashCode;
    }

    public static bool operator == (Int2Key l, Int2Key r)
    {
        return l.data1 == r.data1 && l.data2 == r.data2;
    }

    public static bool operator !=(Int2Key l, Int2Key r)
    {
        return !(l == r);
    }
}

public struct Int3key : IEqualityComparer<Int3key>
{
    public int data1;
    public int data2;
    public int data3;

    public Int3key(int _data1, int _data2, int _data3)
    {
        data1 = _data1;
        data2 = _data2;
        data3 = _data3;
    }

    public bool Equals(Int3key x, Int3key y)
    {
        return x.Equals(y);
    }

    public override bool Equals(object obj)
    {
        return obj is Int3key && this == (Int3key)obj;
    }

    public bool Equals(Int3key y)
    {
        return this == y;
    }

    public override int GetHashCode()
    {
        int hashCode = data1.GetHashCode();
        if (hashCode != data2.GetHashCode())
            hashCode ^= data2.GetHashCode();

        if ( hashCode != data3.GetHashCode() )
            hashCode ^= data3.GetHashCode();
 
        return hashCode;
    }

    public int GetHashCode(Int3key y)
    {
        int hashCode = y.data1.GetHashCode();
        if (hashCode != y.data2.GetHashCode())
            hashCode ^= y.data2.GetHashCode();

        if (hashCode != y.data3.GetHashCode())
            hashCode ^= y.data3.GetHashCode();

        return hashCode;
    }

    public static bool operator == (Int3key l, Int3key r)
    {
        return l.data1 == r.data1 && l.data2 == r.data2 && l.data3 == r.data3;
    }

    public static bool operator !=(Int3key l, Int3key r)
    {
        return !(l == r);
    }
}
